using UnityEngine;
using System.Collections;
using Phidgets;
using Phidgets.Events;

public class Menu : MonoBehaviour {
	
	public static int launch = 0;
	public static int whichSensorMenu = 5;
	bool launched = false;
	
	InterfaceKit ifKitMenu;
	
	// Use this for initialization
	void Start () {
	
		try
		{
			//Initialize the InterfaceKit object
     		ifKitMenu = new InterfaceKit();	
			
			
			//Specific event handler
			ifKitMenu.InputChange += new InputChangeEventHandler(ifKitMenu_InputChange);
			ifKitMenu.SensorChange += new SensorChangeEventHandler(ifKitMenu_SensorChange);
		                
			//Open the object for device connections
        	ifKitMenu.open();
		
			//ifKit.waitForAttachment();
			ifKitMenu.waitForAttachment(3000);
			
					
		}		
		catch
		{
			System.Console.WriteLine("Phidget issues");			
		}
	}
	
	// Update is called once per frame
	void Update () {
		
		launch = ifKitMenu.sensors[3].Value;
		
		if(launch > 40 && !launched)
		{
			launched = true;
			Application.LoadLevel(1);			
		}
		
	}
	
	static void ifKitMenu_InputChange(object sender, InputChangeEventArgs e)
    {
		print("Input "+ e.Index +" value "+ e.Value.ToString());
		whichSensorMenu = e.Index;
	}
	
	static void ifKitMenu_SensorChange(object sender, SensorChangeEventArgs e)
    {
		print("Sensor "+ e.Index +" value "+ e.Value);		
        whichSensorMenu = e.Index;
	}
}
